import os
import sys

import segyio
import numpy as np

# 定义终端输出的颜色代码
BRIGHT = '\033[1m'
BLUE = '\033[94m'
GREEN = '\033[92m'
RED = '\033[91m'
RESET = '\033[0m'


def compare_segy_files(file1, file2, start_trace=0, error_threshold=1e-5, relative_error_threshold=0.001):
    with segyio.open(file1, "r", endian='little', ignore_geometry=True) as segy1, \
            segyio.open(file2, "r", endian='little', ignore_geometry=True) as segy2:
        # 读取所有迹线数据并转换为 NumPy 数组
        traces1 = np.array([trace for trace in segy1.trace[:]])
        traces2 = np.array([trace for trace in segy2.trace[:]])

        # 比较每个迹线的道头信息
        print(segy1.header[1])
        header_diff = []
        for trace_index in range(segy1.tracecount):
            header_1 = segy1.header[trace_index]
        #     print(f'file1---{header_1}')
            header_2 = segy2.header[trace_index]

            if header_1 != header_2:
                header_diff.append(trace_index)
                print(f'file1---{header_1}')
                print(f'file2---{header_2}')
                #print(f"Trace headers 在索引 {trace_index} 处不一致！")
                # print(f'不一致的Trac headers 信息为：')
                # print(f"文件 {BLUE}{file1}{RESET} : {header_1}")
                # print(f"文件 {BLUE}{file2}{RESET} : {header_2}")
        # print(f'file1---{header_1}')
        # print(f"header diff list ：\n{header_diff}")
        # print(f"header diff num : {len(header_diff)}")



# fil1='chai_08_CMPgather_standard_out_arm.segy'
# file2='chai_08_CMPgather_standard_out_x86.segy'
# compare_segy_files(fil1,file2)
if __name__ == '__main__':
    # 从命令行参数获取文件路径
    # if len(sys.argv) < 3:
    #     print("请提供两个 SEG-Y 文件的路径作为参数，第一个参数为arm环境segy，第二个为x86环境segy文件")
    #     sys.exit(1)

    file1_path = sys.argv[1]
    file2_path = sys.argv[2]
    # 如果提供了第三个参数，则将其作为开始迹线的编号；否则，默认为0

    compare_segy_files(file1_path, file2_path)
